package com.example.demofx.dbHelper;

import java.sql.Connection;
import java.sql.ResultSet;

public class DBTst {
    public static void main(String[] args){
        String dbUser = "root";
        String dbPassword ="root";
        String dbName="test";
        String connUrl = "jdbc:mysql://localhost:3306/"+ dbName+"?useUnicode=true&useSSL=false";
        Connection conn=DBHelper.getMySQLConnection(connUrl,dbUser,dbPassword);

     /*   String sqlInsert="insert into test1(IP,Location) values('444.555.666','天空省大地市')";
        int reFlag = DBHelper.executeUpdate(conn, sqlInsert);
        if(reFlag>0){
            System.out.println("新增成功");
        }
      */


        String sqlQuery ="select * from test1";
        ResultSet rs = DBHelper.executeQuery(conn,sqlQuery);
        try{
            int i = 0;
            while (rs.next()){
                i++;
                System.out.println(rs.getString("IP"));
                System.out.println(rs.getString("Location"));
            }
            if(i==0){
                System.out.println("数据库没有记录");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
